package yijy.base;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by yijy on 2017/10/12.
 */
public class B {

    public static String DateFormat(){
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd:HH:mm:ss");
        String str_date = sdf.format(d);
        return str_date;
    }
    public static void main(String[] args){
        try {
            int[] arr = new int[2];
            if(arr[3]>0){
                System.out.println(1);
            }
        } catch (Exception e) {
            e.printStackTrace();
            BufferedWriter bufferedWriter = null;
            try {//将抛出的异常写入到文件中，形成日志文件//改变异常的输出格式
                String dateString =DateFormat()+":"+e;
                bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D://log.txt")));
                bufferedWriter.write(dateString);
            } catch (IOException e1) {
                e1.printStackTrace();
                throw new RuntimeException("日志文件生成失败!"+e1);
            } finally{
                if(bufferedWriter != null){
                    try {
                        bufferedWriter.close();
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }
    }

}
